<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
    var tables = $('#dataTables').DataTable({
        "sAjaxSource" : "{{ urlfor "CollectfeesController.Logs"}}"
        ,"bLengthChange": false
        ,"fnServerData" : function(sSource, aoData, fnCallback) {
            var params = checkQueryTableData(aoData);
            $('#search_key').val() ? params.filter = $('#search_key').val() : '';
            $('#start_date').val() ? params.start_date = $('#start_date').val() : '';
            $('#end_date').val() ? params.end_date = $('#end_date').val() : '';
            $.post(sSource, JSON.stringify(params),function(resp) {
                fnCallback(resp);
            },'json')
        }
        ,columns: [
            {"mDataProp" : "id", "bSortable": false}
            ,{"data" : "number", "bSortable": false, render:function(data, type, full, meta) {
                    return '<span data-status="'+ (full.parent_id?1:0) +'">'+full.number+'</span>';
             }}
            ,{"mDataProp" : "archives.Realname","bSortable": false}
            ,{"mDataProp" : "archives.Sex","bSortable": false}
            ,{"mDataProp" : "archives.Age","bSortable": false}
            ,{"mDataProp" : "total_money","bSortable": false}
            ,{"mDataProp" : "sum_payable","bSortable": false}
            ,{"data" : "created_at", "bSortable": false, render:function(data, type, full, meta) {
                    return timetrans(data);
             }}
            ,{"mDataProp" : "created_by","bSortable": false}
            ,{
                "mDataProp": "Action",
                "bSortable": false,
                "sWidth":"10%",
                "render": function ( data, type, full, meta ) {
                    var btns = '';
                    btns += '<a class="am-btn am-btn-secondary am-btn-xs" href="javascript:;" onclick="return logs_detail('+ full.id +')">明细</a>';
                    if(full.parent_id == 0 && full.status == 0){
                        btns += '&nbsp;<a href="javascript:;" class="am-btn am-btn-danger am-btn-xs" onclick="logs_out('+ full.id +');return false;">退费</a>';
                    }
                    return btns;
                }
            }
        ]
        ,"aLengthMenu":[20, 50, 100, 200]
        ,'bLengthChange': true
        ,"serverSide": true
        ,"bPaginate" : false
        ,"bFilter" : false	//是否启动过滤、搜索功能
        ,"bInfo" : false //是否显示页脚信息，DataTables插件左下角显示记录数
        ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
        ,"drawCallback": function ( settings ) {
            $('#dataTables').find('[data-status="1"]').parent().parent().css({'color':'red'});
        }
    });

    $("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
        $("#dataTables").dataTable().fnDraw(false);
    });

    function logs_detail(id) {
        var url = '{{ urlfor "CollectfeesController.LogsDetail"}}' + '?id=' + id;
        layer.open({
            type: 2,
            title: false,
            shadeClose: false,
            shade: 0.2,
            maxmin: false,
            shift: 1,
            area: ['80%', '60%'],
            content: url
        });
        return false;
    }
    function logs_out(id) {
        var url = '{{ urlfor "CollectfeesController.LogsOut"}}' + '?id=' + id;
        var index = layer.open({
            type: 2,
            title: '门诊退费',
            shadeClose: false,
            shade: 0.2,
            maxmin: false,
            shift: 1,
            area: ['80%', '90%'],
            content: url
        });
        return false;
    }
    function dialogReback() {
        tables.ajax.reload();
    }

</script>